package com.open.capacity.salary.controller;

import java.util.Map;

import com.open.capacity.commons.Result;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.salary.entity.GzEnableMonth;
import com.open.capacity.salary.service.GzEnableMonthService;

import com.open.capacity.commons.PageResult;

import javax.validation.Valid;

/**
 * 工资系统启用月份
 *
 * @author
 * @email
 * @date 2021-08-02 14:26:51
 */
@RestController
@RequestMapping("gzenablemonths")
@Api(tags = "工资系统启用月份")
public class GzEnableMonthController {

    @Autowired
    private GzEnableMonthService gzEnableMonthService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('gz_enable_month:gzenablemonth:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = gzEnableMonthService.pageAll(params);
        return pageResult;
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findByZtId")
    @PreAuthorize("hasAnyAuthority('gz_enable_month:gzenablemonth:list')")
    public Result findByZtId(String companyId, String ztId) {
        return Result.succeed(gzEnableMonthService.findByZtIdWithoutException(companyId, ztId));
    }


    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('gz_enable_month:gzenablemonth:save')")
    public Result save(@RequestBody @Valid GzEnableMonth gzEnableMonth) {
        gzEnableMonthService.save(gzEnableMonth);
        return Result.succeed("保存成功");
    }

    /**
     * 月结
     */
    @RequestMapping("/nextMonth")
    @PreAuthorize("hasAnyAuthority('gz_enable_month:gzenablemonth:save')")
    public Result nextMonth(String companyId, String ztId) {
        gzEnableMonthService.next(companyId, ztId);
        return Result.succeed("月结成功");
    }


    /**
     * 反月结
     */
    @RequestMapping("/preMonth")
    @PreAuthorize("hasAnyAuthority('gz_enable_month:gzenablemonth:save')")
    public Result preMonth(String companyId, String ztId) {
        gzEnableMonthService.pre(companyId, ztId);
        return Result.succeed("反月结成功");
    }
}
